import { createI18n } from 'vue-i18n'
import zhCn from './zh-cn'
import en from './en'

const messages = {
  'zh-cn': zhCn,
  en: en
}

// 获取浏览器语言设置
const getDefaultLocale = () => {
  const locale = navigator.language.toLowerCase()
  if (locale.startsWith('zh')) {
    return 'zh-cn'
  }
  return 'en'
}

const i18n = createI18n({
  legacy: false,
  locale: getDefaultLocale(),
  fallbackLocale: 'en',
  messages
})

export default i18n
